package pl.put.to.regression;

import java.io.IOException;
import java.util.List;

import pl.put.to.regression.data.DataSet;
import pl.put.to.regression.verification.IErrorVeryficator;
import pl.put.to.regression.verification.LADErrorVefyficator;
import pl.put.to.regression.verification.LSErrorVefyficator;
import pl.put.to.regression.verification.MMErrorVefyficator;

public class LeastSquaresEntryPoint {
	public static void main(String[] args) {
		try {
			DataSet trainDataSet = new DataSet("data/DenBosch_train.data");

			long t0 = System.nanoTime();
			
			LeastSquaresProblem lsProblem = new LeastSquaresProblem(trainDataSet);
			lsProblem.solve();

			long t1 = System.nanoTime();
			
			System.out.println("Time: " + ((t1 - t0) / 1000000) + " ms");
			
			List<Double> coefficients = lsProblem.getCoefficients();
			System.out.println("coefficients = " + coefficients.toString());
			
			DataSet testDataSet = new DataSet("data/DenBosch_test.data");

			IErrorVeryficator errorVeryficator = new LSErrorVefyficator();
			double lsErrorTrain = errorVeryficator.countError(trainDataSet, coefficients);
			double lsErrorTest = errorVeryficator.countError(testDataSet, coefficients);

			errorVeryficator = new LADErrorVefyficator();
			double ladErrorTrain = errorVeryficator.countError(trainDataSet, coefficients);
			double ladErrorTest = errorVeryficator.countError(testDataSet, coefficients);

			errorVeryficator = new MMErrorVefyficator();
			double mmErrorTrain = errorVeryficator.countError(trainDataSet, coefficients);
			double mmErrorTest = errorVeryficator.countError(testDataSet, coefficients);

			System.out.println("LS error on train set = " + lsErrorTrain);
			System.out.println("LS error on test set = " + lsErrorTest);
			System.out.println("LAD error on train set = " + ladErrorTrain);
			System.out.println("LAD error on test set = " + ladErrorTest);
			System.out.println("MM error on train set = " + mmErrorTrain);
			System.out.println("MM error on test set = " + mmErrorTest);
			
		} catch (IOException e) {
			e.printStackTrace();
		}

	}
}
